package com.tepth.remote.core.net.soap;

import android.content.Context;

import com.tepth.remote.core.net.callback.IError;
import com.tepth.remote.core.net.callback.IFailure;
import com.tepth.remote.core.net.callback.IRequest;
import com.tepth.remote.core.net.callback.ISoapSuccess;
import com.tepth.remote.core.net.loader.LoaderStyle;

import java.util.WeakHashMap;

/**
 * Description:Soap请求构造类
 *
 * @author Hequn.Lee
 * @date 2018/11/8
 */
public class SoapClientBuilder {

    /**
     * 请求参数
     */
    private final WeakHashMap<String, Object> PARAMS = new WeakHashMap<>();
    /**
     * 请求回调
     */
    private IRequest mRequest = null;
    /**
     * 成功请求回调
     */
    private ISoapSuccess mSuccess = null;
    /**
     * 失败请求回调
     */
    private IFailure mFailure = null;
    /**
     * 网络错误回调
     */
    private IError mError = null;
    /**
     * 上下文
     */
    private Context mContext = null;
    /**
     * 命名空间
     */
    private String mNameSpace = null;
    /**
     * 请求方法名
     */
    private String mMethodName = null;
    /**
     * 菊花样式
     */
    private LoaderStyle mLoaderStyle = null;

    SoapClientBuilder() {
    }

    /**
     * 传入请求参数集合
     *
     * @param params 请求参数集合
     * @return 构造类
     */
    public final SoapClientBuilder params(WeakHashMap<String, Object> params) {
        PARAMS.putAll(params);
        return this;
    }

    /**
     * 传入请求参数
     *
     * @param key   参数名
     * @param value 参数值
     * @return 构造类
     */
    public final SoapClientBuilder params(String key, Object value) {
        PARAMS.put(key, value);
        return this;
    }

    /**
     * 请求回调
     *
     * @param request 请求回调
     * @return 构造类
     */
    public final SoapClientBuilder onRequest(IRequest request) {
        this.mRequest = request;
        return this;
    }

    /**
     * 传入成功请求的回调
     *
     * @param success 成功回调接口
     * @return 构造类
     */
    public final SoapClientBuilder success(ISoapSuccess success) {
        this.mSuccess = success;
        return this;
    }

    /**
     * 传入失败请求的回调
     *
     * @param failure 失败回调接口
     * @return 构造类
     */
    public final SoapClientBuilder failure(IFailure failure) {
        this.mFailure = failure;
        return this;
    }

    /**
     * 传入网络错误的回调
     *
     * @param error 网络错误的回调
     * @return 构造类
     */
    public final SoapClientBuilder error(IError error) {
        this.mError = error;
        return this;
    }

    /**
     * 传入命名空间
     *
     * @param nameSpace 命名空间
     * @return 构造类
     */
    public final SoapClientBuilder nameSpace(String nameSpace) {
        this.mNameSpace = nameSpace;
        return this;
    }

    /**
     * 传入请求方法名
     *
     * @param methodName 请求方法名
     * @return 构造类
     */
    public final SoapClientBuilder methodName(String methodName) {
        this.mMethodName = methodName;
        return this;
    }

    /**
     * 传入自定义菊花样式
     *
     * @param context 上下文
     * @param style   菊花样式
     * @return 构造类
     */
    public final SoapClientBuilder loader(Context context, LoaderStyle style) {
        this.mContext = context;
        this.mLoaderStyle = style;
        return this;
    }

    /**
     * 传入默认菊花样式
     *
     * @param context 上下文
     * @return 构造类
     */
    public final SoapClientBuilder loader(Context context) {
        this.mContext = context;
        this.mLoaderStyle = LoaderStyle.BallClipRotatePulseIndicator;
        return this;
    }

    /**
     * 构造Soap连接类
     *
     * @return Soap连接类
     */
    public final SoapClient builder() {
        return new SoapClient(
                PARAMS,
                mNameSpace,
                mMethodName,
                mRequest,
                mSuccess,
                mFailure,
                mError,
                mContext,
                mLoaderStyle);
    }
}
